﻿(function (D) {
    var C = { action: "Summer.Action.ashx", resource: "Summer.Resource.ashx" };
    var A = {}; var B = {};
    window.$g = { setHandlerPath: function (E, G, F) {
        if (G) { G = "/" + G }
        else { G = "/Summer.Action.ashx" }
        if (F) { if (typeof F == "object") { F = D.param(F) } F = "?" + F }
        else { F = "" } C.action = E + G + F; C.resource = E + "/Summer.Resource.ashx" + F
    },
        action: function (K, I, F, E, L, H, J) {
            if (D.isFunction(F)) { J = H; H = L; L = E; E = F; F = {} } J = J || "json"; L = L || "";
            var G = { a: I, d: D.toJSON(F), m: K, n: L }; D.post(H || C.action, G, E, J)
        },
        getTemplate: function () {
            var E = D.makeArray(arguments).join(".").toLowerCase();
            if (B[E]) { return B[E] } else { return false }
        },
        registerTemplate: function () {
            var E = D.makeArray(arguments).slice(0, -1).join(".").toLowerCase();
            B[E] = arguments[arguments.length - 1]
        },
        getPlugin: function () {
            var E = D.makeArray(arguments).join(".").toLowerCase();
            if (A[E]) { return A[E] } else { return false }
        },
        registerPlugin: function () {
            var E = D.makeArray(arguments).slice(0, -1).join(".").toLowerCase();
            A[E] = arguments[arguments.length - 1]
        },
        requireResource: function () {
            var O = arguments[0]; var G = arguments.length - 1; var I = null; var F = arguments[G];
            if (!D.isFunction(F)) {
                if (G > 0) {
                    F = arguments[G - 1]; if (D.isFunction(F)) { I = arguments[G] }
                    else {
                        F = null; if (D.isArray(O)) { if (arguments.length == 2) { I = arguments[G] } }
                        else {
                            if (arguments.length == 4) { I = arguments[G] }
                            else {
                                if (arguments.length == 3) {
                                    var H = arguments[G];
                                    if (H != "script" && H != "template") { I = H }
                                }
                            }
                        }
                    }
                }
                else { F = null }
            } if (D.isArray(O)) {
                if (O.length) {
                    var M = O.shift();
                    $g.requireScript(M.module, M.action, M.type, function () {
                        if (O.length) { $g.requireScript(O, F, I) }
                        else { if (F) { F() } }
                    }, I)
                }
            } else {
                var N = arguments[0]; var K = arguments[1]; var L = arguments[2];
                if (typeof L !== "string") { L = this.type }
                if (L === "script") {
                    var J = $g.getPlugin(N, K); if (J) { if (F) { F(J) } }
                    else {
                        D.getScript((I || C.resource) + "?a=" + encodeURIComponent(K) + "&m=" + encodeURIComponent(N),
 function () { J = $g.getPlugin(N, K); if (!J) { $g.registerPlugin(N, K, true) } if (F) { F(J) } })
                    }
                }
                else {
                    if (L == "template") {
                        var E = $g.getTemplate(N, K); if (E) { if (F) { F(E) } }
                        else {
                            D.get((I || C.resource) + "?t=template&a=" + encodeURIComponent(K) + "&m=" + encodeURIComponent(N),
 function (P) { E = P; $g.registerTemplate(N, K, E); if (F) { F(E) } })
                        }
                    }
                }
            }
        },
        requireScript: function () {
            var E = { type: "script" };
            this.requireResource.apply(E, arguments)
        },
        requireTemplate: function () {
            var E = { type: "template" };
            this.requireResource.apply(E, arguments)
        },
        getForm: function (E) {
            E = D(E); var F = {}; D(":input", E).filter(":not(:button)").each(function () {
                var G = D(this);
                var H = G.attr("field") || G.attr("name") || G.attr("id");
                if (G.is(":checkbox,:radio")) { if (!G.attr("checked")) { return } }
                if (F[H]) { var I = F[H]; if (!D.isArray(I)) { I = [I]; F[H] = I } I.push(G.val()) }
                else { F[H] = G.val() }
            }); return F
        },
        setForm: function (E, F) {
            E = D(E);
            D(":input,", E).filter(":not(:button)").each(function () {
                var G = D(this); var H = G.attr("name");
                if (F[H] != undefined) {
                    var I = F[H]; if (D.isArray(I)) { G.attr("checked", D.inArray(G.val(), I) != -1) }
                    else {
                        if (G.is(":radio,:checkbox")) {
                            if (typeof I === "boolean") { G.attr("checked", I) }
                            else { G.attr("checked", G.val() == I) }
                        } else { G.val(I) }
                    }
                }
            })
        },
        initForm: function (E) {
            window.CKEDITOR_BASEPATH = "ckeditor/JS/";
            var F = [{ module: "jquery", action: "ckeditor" }, { module: "jquery", action: "ui.i18n" }, { module: "jquery", action: "maskedinput" }, { module: "jquery", action: "bgiframe" }, { module: "jquery", action: "lv.iform" }, { module: "jquery", action: "swfobject" }, { module: "jquery", action: "uploadify"}];
            $g.requireScript(F, function () {
                E.iform(); var I = D(".ui-editor", E); if (I.size() > 0) { I.ckeditor() }
                var G = D(".ui-datepicker", E); if (G.size()) {
                    G.each(function () {
                        var K = D(this);
                        var L = K.val(); if (/\d+\/\d+\/\d+/.test(L)) {
                            L = L.split(" ")[0].split("/");
                            for (var J = L[0].length; J < 4; J++) { L[0] = "0" + L[0] }
                            for (var J = L[1].length; J < 2; J++) { L[1] = "0" + L[1] }
                            for (var J = L[2].length; J < 2; J++) { L[2] = "0" + L[2] } K.val(L.join("-"))
                        }
                    });
                    D.datepicker.setDefaults(D.datepicker.regional["zh-CN"]); G.datepicker().mask("9999-99-99")
                }
                var H = D(".ui-uploader", E); window._uploaders = window._uploaders || 1;
                H.each(function () {
                    var O = D(this); if (!O.attr("id")) { O.attr("id", "_uploader_" + (window._uploaders++)) }
                    var L = O.metadata(); var K = "*.jpg;*.jpeg;*.bmp;*.gif;*.png"; var M = "*.jpg;*.jpeg;*.bmp;*.gif;*.png";
                    var N = "css/images/browse.gif"; var J = "css/images/delete.gif"; O.parent().css("position", "relative");
                    O.uploadify({ "uploader": "Uploader/uploadify.swf",
                        "script": "Uploader/Uploader.aspx",
                        multi: L.multi == null ? false : L.multi,
                        buttonText: L.text || "", fileExt: L.exts || K,
                        fileDesc: L.extsdesc || M,
                        auto: L.auto == null ? true : L.auto, wmode: "transparent",
                        buttonImg: L.img || N, cancelImg: L.cancelImg || J
                    })
                })
            })
        }
    };
    D(function () {
        D("div.iwidget").each(function () {
            var F = D(this); var G = F.attr("iwidget");
            var E = F.attr("iwidget-action"); var H = parseInt(F.attr("iwidget-auto"));
            if (!H) { H = 1 } if (!E) { E = G }
            $g.requireScript(G, E, function () { if (H) { F[G]() } }, "Widgets/Summer.Resource.ashx")
        })
    });
    $g.sm = function (F, E) { this.mid = F; this.tid = E };
    $g.sm.prototype = { action: function (E, H, G) {
        var F = { _s_a: E, _s_d: D.toJSON(H) };
        D.post(location.pathname + "?tabid=" + this.tid + "&mid=" + this.mid, F, G, "json")
    }
    }
})(jQuery);